<?php
namespace app\admin\controller;

use app\admin\service\ProjectService;
use think\Controller;

class Project extends Controller
{
    private $projectService;

    /**
     * 依赖注册
     * Charging constructor.
     * @param ProjectService $projectService
     */
    public function __construct(ProjectService $projectService)
    {
        $this->projectService = $projectService;
        parent::__construct();
    }

    /**
     * 查询充电桩项目列表
     * User: zhouyao
     * Date: 2018/9/8
     * Time: 下午2:29
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function postIndex()
    {
        $input = $this->request->input;

        $result = $this->projectService->index($input);
        return app_response(200, $result);
    }

    /**
     * 添加充电桩项目信息
     * User: zhouyao
     * Date: 2018/9/8
     * Time: 下午2:11
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function postStore()
    {
        $input = $this->request->input;
        $result = $this->projectService->store($input);
        $code = 200;
        if ($result === false) {
            $code = 9996;
        }

        return app_response($code, $result);
    }

    /**
     * 查询指定充电桩数据
     * User: zhouyao
     * Date: 2018/9/8
     * Time: 下午1:55
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function postEdit()
    {
        $input = $this->request->input;
        $result = $this->projectService->edit($input);
        $code = 200;
        if ($result === false) {
            $code = 9998;
        }

        return app_response($code, $result);
    }

    /**
     * 修改充电桩项目信息
     * User: zhouyao
     * Date: 2018/9/8
     * Time: 下午2:11
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     */
    public function postUpdate()
    {
        $input = $this->request->input;
        $result = $this->projectService->update($input);
        $code = 200;
        if ($result === false) {
            $code = 9998;
        }

        return app_response($code, '操作成功');
    }

    /**
     * 获取所有顶级类型
     * User: zhouyao
     * Date: 2018/9/9
     * Time: 下午9:53
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function postCate()
    {
        $input = $this->request->input;
        $result = $this->projectService->cate($input);
        return app_response(200, $result);
    }
}